import SwiftUI
import SPGlassKit

public struct GlassSecureFieldExample: GlassExample {
    public static let componentID = "glass-secure-field"
    @State private var current = ""
    @State private var new = ""
    @State private var pin = ""

    public init() {}

    public var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 20) {
                GlassSecureField("Current password", text: $current, validation: GlassFieldValidation(.required()))

                GlassSecureField(
                    "New password",
                    text: $new,
                    prompt: "At least 12 characters",
                    helper: "Use a phrase you can remember.",
                    content: .newPassword,
                    allowsReveal: true,
                    validation: GlassFieldValidation(.required(), .minLength(12)),
                    validateOn: .always
                )

                GlassSecureField("Device PIN", text: $pin, allowsReveal: true, errorMessage: pin.isEmpty ? nil : "Demo: this PIN is always rejected.")

                // Only the length is ever displayed: the example never prints the secret.
                Text("New password length: \(new.count)")
                    .font(.callout)
                    .foregroundStyle(.secondary)
            }
            .padding()
        }
    }
}

#Preview("GlassSecureField") { GlassSecureFieldExample() }
